﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using X.Web;
using X.Entity;
using System.Web.UI.HtmlControls;

namespace X.WebSite.Product
{
    public partial class List : PageBase
    {
        ProductCategoryInfo _CategoryInfo
        {
            get
            {
                ProductCategoryInfo categoryInfo;
                int categoryId = 0;

                string categoryName = string.Empty;

                if (!string.IsNullOrEmpty(Request.QueryString["CategoryName"]))
                    categoryName = Request.QueryString["CategoryName"];

                categoryName = X.Common.StringUtils.UrlToString(categoryName, ref categoryId);

                categoryInfo = (ProductCategoryInfo)ViewState[categoryName];

                if (null != categoryInfo)
                    return categoryInfo;

                if (0 != categoryId)
                    categoryInfo = Bll.ProductCategory.GetCategory(categoryId);
                else
                    categoryInfo = Bll.ProductCategory.GetCategory(categoryName);

                return categoryInfo;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                lblCategoryName.Text = _CategoryInfo.CategoryName;
                lblCategoryDescription.Text = _CategoryInfo.CategoryDescript;

                this.Title = X.Common.StringUtils.HtmlDecode(_CategoryInfo.Title) + this.Title;
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            //Keywords
            HtmlMeta keywords = new HtmlMeta();
            keywords.Name = "keywords";
            keywords.Content = _CategoryInfo.Keyword;
            Header.Controls.Add(keywords);

            //Description
            HtmlMeta description = new HtmlMeta();
            description.Name = "description";
            description.Content = _CategoryInfo.Descript;
            Header.Controls.Add(description);
        }
    }
}